package cst.a903dss.zyfypt_903dss.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import cst.a903dss.zyfypt_903dss.AmicoolListener;
import cst.a903dss.zyfypt_903dss.adapter.ArticleAdapter;
import cst.a903dss.zyfypt_903dss.Bean.ArticleBean;
import cst.a903dss.zyfypt_903dss.R;
import cst.a903dss.zyfypt_903dss.ResModel;


/**
 * A simple {@link ArticleFragment} subclass.
 */

public class ArticleFragment extends BaceFragment {
    private RecyclerView recyclerView;
    private ArticleAdapter adapter;
    private List<ArticleBean> list;
    private RecyclerView.LayoutManager layoutManager;
    private AmicoolListener<List<ArticleBean>> listener;
    private ResModel model;

   // private SharedPreferences sp;
    @Nullable
    @Override
    public View onCreateView( LayoutInflater inflater, @Nullable ViewGroup container,@Nullable Bundle savedInstanceState) {
       View view=inflater.inflate(R.layout.fragment_article,container,false);
        recyclerView=(RecyclerView)view.findViewById(R.id.article_rec);
        adapter=new ArticleAdapter(getActivity());
        /*adapter.setOnItemClickListener(new ArticleAdapter.OnItemClickListener(){
            @Override
            public void onItemClick(View view, int position){
                Intent intent;
                intent=new Intent(getActivity(),ArticleActivity.class);
                intent.putExtra("id",list.get(position).getId());
                getActivity().startActivity(intent);
            }
            public void onItemLongClick(View view,int position){

            }
        });*/
        //list=new ArrayList<ArticleBean>();
        layoutManager=new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
        listener=new AmicoolListener<List<ArticleBean>>() {
            @Override
            public void onResponse(List<ArticleBean> l) {
                adapter.setList(l);
            }

            @Override
            public void onFail(String msg) {

            }
        };
        //sp=getActivity().getSharedPreferences("ME", Context.MODE_PRIVATE);
        model=new ResModel("gson",getSessionID());
        model.getList("article",1,listener);
        return view;
    }
}
